using System.Collections.Generic;
using SpaceTrader.Core;

namespace Core
{
    public class Game
    {
        protected List<IController> mControllers = new List<IController>();
        protected Logger mLogger = new Logger();
        protected List<GameObject> mObjects = new List<GameObject>();
        public bool Paused = false;

        public Game()
        {
            Logger.Instance().Log("Game started", LogLevel.Info);
        }

        public List<GameObject> Objects
        {
            get { return mObjects; }
        }

        public List<IController> Controllers
        {
            get { return mControllers; }
        }

        public Logger Logger
        {
            get { return mLogger; }
            set { mLogger = value; }
        }

        public void AddObject(GameObject Obj)
        {
            Objects.Add(Obj);
        }

        public void AddController(IController Controller)
        {
            Controller.Game = this;
            Controllers.Add(Controller);
        }

        public void Update()
        {
            if (!Paused)
                // Update the state of each object in the universe.
                foreach (GameObject Obj in Objects)
                {
                    Obj.Update();
                }

            Render();
        }

        public void Render()
        {
            // Notify any controllers to re-render.
            foreach (IController Controller in Controllers)
            {
                Controller.Render();
            }
        }
    }
}